import axios from '@/utils/request'
//引入接口数据类型
import { DataC, AttrListResponseData, Attr } from './type'
//定义接口地址枚举
enum API {
  //获取第一个下拉框的列表
  GETCATEGORYF_URL = '/admin/product/getCategory1',
  //第一个下拉框选中后把1id传回获取第二个下拉框的值列表
  GETCATEGORYS_URL = '/admin/product/getCategory2/',
  //第二个下拉框选中后把1id传回获取第三个下拉框的值列表
  GETCATEGORYT_URL = '/admin/product/getCategory3/',
  //三个都选好后获取attr列表的值
  GETATTRLIST_URL = '/admin/product/attrInfoList/',
  //attrlist新增属性值或修改
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  //删除属性
  DELETEATTR_URL = '/admin/product/deleteAttr/',
}
//获取第一个分类下拉框的值
export const getCategory1 = () => axios.get<any, DataC>(API.GETCATEGORYF_URL)
//获取第二个分类下拉框的值
export const getCategory2 = (c1Id: number | string) =>
  axios.get<any, DataC>(API.GETCATEGORYS_URL + c1Id)
//获取第三个分类下拉框的值
export const getCategory3 = (c2Id: number | string) =>
  axios.get<any, DataC>(API.GETCATEGORYT_URL + c2Id)
//获取属性列表
export const getAttrList = (
  c1Id: number | string,
  c2Id: number | string,
  c3Id: number | string,
) =>
  axios.get<any, AttrListResponseData>(
    API.GETATTRLIST_URL + `${c1Id}/${c2Id}/${c3Id}`,
  )
export const reqAddOrUpdateAttr = (data: Attr) =>
  axios.post<any, any>(API.ADDORUPDATEATTR_URL, data)
export const reqDeleteAttrById = (id: number | string) =>
  axios.delete<any, any>(API.DELETEATTR_URL + id)
